
import axios from 'axios'
import router from "@/router"

axios.interceptors.request.use(config => {
    if (localStorage.getItem('token')) {
        config.headers.token = localStorage.getItem('token');
    }
    return config;
},
    err => {
        return Promise.reject(err);
    });

// 定义响应拦截器
axios.interceptors.response.use(function (response) {
    if (response.data.code == '401') {
        localStorage.removeItem('token')
        router.replace({
            path: '/Login',
        });
    }
    return response
}, function (error) {
    return Promise.reject(error)

})
export default axios